<div class="row container">
<div class="col-md-12">
<div class="panel panel-success">
	
	<div class="panel-heading">
	   <nav>
		    <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#search-menu" style="padding:6px;margin:0px;border:0px">
                    <span class="glyphicon glyphicon-search"></span>
                </button>
                <a href="<?php echo $this->url('events',array('controller'=>'pendingevent','action'=>'add'));?>" class="btn btn-info"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>Add Events &raquo;</a>
            </div>
			<div class="collapse navbar-collapse" id="search-menu">	
			   	<div class="pull-right">			 
					<?php 
                        $searchform=$this->searchform;
                        $searchform->setAttribute('action', $this->url(NULL, array(
                            'controller' => 'pendingevent',
                            'action' => 'search'
                        )));
                        echo $this->form()->openTag($searchform); 
                    ?>   
                        <div class="form-group">
                                <?php   echo $this->formElement($searchform->get('KEY'));?>
                                <span class="errormsgform"><?php   //echo $this->formElementErrors($searchform->get('KEY')); ?></span>
                        </div>
                        
                        <div class="form-group">
                                <?php   echo $this->formElement($searchform->get('CATEGORY')); ?>
                                <span class="errormsgform"><?php  // echo $this->formElementErrors($searchform->get('CATEGORY')); ?></span>
                        </div>
                        
                    	<div class="form-group">
                                <?php echo $this->formElement($searchform->get('BTNSEARCH')); ?>
                    	</div> 
                    <?php 
                        echo $this->form()->closeTag();
                    ?>
                </div>
             </div>
         </nav>
    </div>
	
	<div class="panel-body">
	<div class="table-responsive">
		<table class="table table-bordered table-striped">
				<tr>
				    <th>No</th>
					<th>Title</th>					
				    <th>Date</th>
					<th>Subject</th>
					<th>Category</th>
					<th>Seats</th>
					<th>Place</th>
					<th>Description</th>
					<th>Status</th>
					<th>Options</th>
				</tr>
				<?php $number=0;?>
				<?php foreach ($this->paginator as $event) : ?>
				<tr>
							<td><?php echo ++$number?></td>
							<td><?php echo $this->escapeHtml($event->TITLE);?></td>
							<td><?php echo $this->escapeHtml($event->DATE);?></td>
							<td><?php echo $this->escapeHtml($event->SUBJECT);?></td>
							<td><?php 
        					
        					if($this->escapeHtml($event->CATEGORY)==1){
        						echo "Main";
        					}
        					else if($this->escapeHtml($event->CATEGORY)==2){
        						echo "District";
        					}
        					else if($this->escapeHtml($event->CATEGORY)==3){
        						echo "Regional";
        					}		
        					
        					?></td>
							<td><?php echo $this->escapeHtml($event->SEATS);?></td>
							<td><?php echo $this->escapeHtml($event->PLACE);?></td>
							<td><?php echo $this->escapeHtml($event->DESCRIPTION);?></td>
							<td><?php 
        					
        						if($this->escapeHtml($event->EVENT_STATUS)==1){
        							echo "Pending";
        						}
        						else if($this->escapeHtml($event->EVENT_STATUS)==2){
        							echo "Completed";
        						}
        						
        						?>       					
        					
        					</td>
        					<td>
                                 <div class="btn btn-default"><a href="<?php echo $this->url('events',array('controller'=>'pendingevent','action'=>'edit', 'id' => $event->ID));?>"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span></a></div>
                                 <div class="btn btn-default"><a href="<?php echo $this->url('events',array('controller'=>'EventParticipant','action'=>'Index', 'id' => $event->ID));?>"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></a></div>
                            </td>	        			
        		</tr>
        		<?php endforeach; ?>
		</table>
		<?php 
    		// add at the end of the file after the table
            echo $this->paginationControl(
            // the paginator object
            $this->paginator,
            // the scrolling style
            'sliding',
            // the partial to use to render the control
            'partial/paginator.phtml',
            // the route to link to when a user clicks a control link
            array(
                'route' => 'events'
                )
            );
         ?>
		
	</div>
	</div>
	<div class="pull-right" style="padding:0.2em 0 0 0.2em"><a href="<?php echo $this->url('events',array('controller'=>'pendingevent','action'=>'email'));?>" class="btn btn-info" role="button"><span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> Email &raquo;</a></div>
	<div class="pull-right" style="padding:0.2em 0 0 0.2em"><a class="btn btn-info" role="button" onclick="window.print()" target="_blank"><span class="glyphicon glyphicon-print" aria-hidden="true"></span> Print	&raquo;</a></div>
</div>
</div>
</div>
<script type="text/javascript">
$( document ).ready(function() {
    $('#searchCATEGORY').change(function(){
        initSearchKey();        
        if($('#searchCATEGORY').val() == 'DATE'){
     	   $('#searchKEY').datepicker({ dateFormat: 'yy-mm-dd' });
        }
        if($('#searchCATEGORY').val() == 'EVENT_STATUS'){
       	   $('#searchKEY').suggestions();
        }
    });
    initSearchKey = function(){
    	$('#searchKEY').datepicker( "destroy" );
    	$('#searchKEY').val('');
	};
	suggestions=$(function() {
		    var availableTags = [
		      "pending",
		      "completed"
		    ];

		    $( "#searchKEY" ).autocomplete({
		      source: availableTags
		    });
	});
});
</script>
